// 压力测试
import http from 'k6/http';
import { sleep } from 'k6';

export let options = {
  stages: [
    { duration: '2m', target: 100 }, // 低于正常负载
    { duration: '5m', target: 100 },
    { duration: '2m', target: 200 }, // 正常负载
    { duration: '5m', target: 200 },
    { duration: '2m', target: 300 }, // 在突破点附近
    { duration: '5m', target: 300 },
    { duration: '2m', target: 400 }, // 突破临界点
    { duration: '5m', target: 400 },
    { duration: '10m', target: 0 }, // 缩小。 恢复阶段。
  ],
};

export default function () {
  const BASE_URL = 'https://test-api.k6.io'; // 确保这不是生产

  let responses = http.batch([
    [
      'GET',
      `${BASE_URL}/public/crocodiles/1/`,
      null,
      { tags: { name: 'PublicCrocs' } },
    ],
    [
      'GET',
      `${BASE_URL}/public/crocodiles/2/`,
      null,
      { tags: { name: 'PublicCrocs' } },
    ],
    [
      'GET',
      `${BASE_URL}/public/crocodiles/3/`,
      null,
      { tags: { name: 'PublicCrocs' } },
    ],
    [
      'GET',
      `${BASE_URL}/public/crocodiles/4/`,
      null,
      { tags: { name: 'PublicCrocs' } },
    ],
  ]);

  sleep(1);
}